const Service = require('egg').Service;
class BlogService extends Service {
    async addblog(obj){
        let {title,img,content,name} = obj;
        let res = await this.app.mysql.query(`insert into blog (title,content,name,img,time) values ('${title}','${content}','${name}','${img}',now())`);
        return res;
    }
    async delblog(id){
        let res = await this.app.mysql.query(`delete from blog where id=${id}`);
        return res;
    }
    async updateblog(obj){
        let {title,img,content,name,id} = obj;
        let res = await this.app.mysql.query(`update blog set title='${title}',content='${content}',name='${name}',img='${img}',time=now() where id=${id}`);
        return res;
    }
    async listblog(){
        let res = await this.app.mysql.query('select * from blog');
        return res;
    }
}

module.exports = BlogService;